#include "Comm.hpp"

int main()
{
    FIFO fifo(Path);
    int rfd = open(Path, O_RDONLY);
    if (rfd < 0)
    {
        cerr << "open failed" << "errno:" << errno << "strerror:" << strerror(errno) << endl;
        return 1;
    }
    // 读端返回值，只有写端创建出来后，读端才有返回值
    cout << "open success~" << endl;
    char buffer[1024];
    while (true)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            buffer[n] = '\0';
            cout << "Client say:" << buffer << endl;
        }
        else if (n == 0)
        {
            cout << "client quit... me too" << endl;
            break;
        }
        else
        {
            cerr << "read failed..." << "errno:" << errno << "strerror" << strerror(errno) << endl;
            return 1;
        }
    }
    close(rfd);
    return 0;
}